package com.backend_pay.service;

import com.backend_pay.dao.UserDao;
import com.backend_pay.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;


@Service //业务层bean
public class UserService {
    //自动注入UserDao
    @Autowired
    UserDao userDao;

    //增、删、改、查

    //查
    public User findByName(String name){
        return userDao.findByName(name);
    }
    public User findByUserid(Integer id){
        return userDao.findByUserid(id);
    }
    //保存
    public void save(User user){
         userDao.save(user);
    }
    public Optional<User> findById(Integer id){
        return userDao.findById(id);
    }
    //保存用户，原生insert SQL
    public void savaNewUser(String name,String password){
        userDao.savaNewUser(name,password);
    }
    //删除用户
    public void deleteUserById(Integer id){
        userDao.deleteUserById(id);
    }
}
